-- We use creatura bats now, remove old ones
minetest.register_entity(":mobs_creatures:bat", {on_activate = function(self) self.object:remove() end})

-- Disable inbuilt function because it doesn't tell the last login
minetest.send_join_message = function(_player_name) end

-- Implement it ourselves
minetest.register_on_joinplayer(function(player_ref, last_login)
    local msg
    if last_login then
        msg = "*** Welcome back, " .. player_ref:get_player_name() .. "!"

        local passed_time = os.time() - last_login
        local one_month = 730 * 3600

        if passed_time > one_month then
            local months = math.floor(passed_time / one_month)
            local number_text = ({
                [1] = "one",
                [2] = "two",
                [3] = "three",
                [4] = "four",
                [5] = "five",
                [6] = "six",
                [7] = "seven",
                [8] = "eight",
                [9] = "nine",
                [10] = "ten",
                [11] = "eleven",
                [12] = "twelve"
            })[months] or tostring(months)

            msg = msg .. " It's been " .. number_text .. " month" .. (months == 1 and "" or "s") .. "!"
        end
    else
        msg = "*** " .. player_ref:get_player_name() .. " is joining for the first time! Welcome to Centeria!"
    end
    minetest.chat_send_all(msg)
end)

-- Convert signs nodes to signs_lib
-- Aliases for the nodes. Node appearance ajusts automatically
minetest.register_alias("signs:sign", "default:sign_wood_yard")
minetest.register_alias("signs:wall_sign", "default:sign_wall_wood")
-- Delete old text entities
minetest.register_entity(":signs:sign_text", {on_activate = function(self) self.object:remove() end})
